package com.szxy.hotel.mapper;

import com.szxy.hotel.entity.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoomMapper {

    @Insert("insert into room (room_id,room_type,room_price,room_state,room_reserve,room_expire,room_in,room_out,room_name,room_time,room_remark) " +
            "values(#{room.roomId},#{room.roomType},#{room.roomPrice},#{room.roomState},#{room.roomReserve}," +
            "#{room.roomExpire},#{room.roomIn},#{room.roomOut},#{room.roomName},#{room.roomTime},#{room.roomRemark})")
    @ResultMap("RoomResultMap")
    int insertRoom(@Param("room") Room room);

    @Select("select * from room where room_id = #{roomId}")
    @ResultMap("RoomResultMap")
    Room findByroomid(@Param("roomId") String roomId);

    @Update("update room set room_reserve=#{room.roomReserve},room_expire=#{room.roomExpire},room_remark=#{room.roomRemark} " +
            "where room_id=#{room.roomId}")
    @ResultMap("RoomResultMap")
    void updateDate(@Param("room") Room room);

    @Select("select * from room where room_state = #{roomtype} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPage(@Param("start") int start,@Param("size") int size,@Param("roomtype") String roomtype);

    @Select("select * from room where room_state = #{roomtype}")
    @ResultMap("RoomResultMap")
    List<Room> selectCount(@Param("roomtype") String roomtype);

    @Select("select * from room where room_state = #{roomtype} and room_name = #{userName3} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPageSearch(@Param("start") int start,@Param("size") int size,@Param("roomtype") String roomtype,@Param("userName3") String userName3);

    @Select("select * from room where room_state = #{roomtype} and room_name = #{userName3}")
    @ResultMap("RoomResultMap")
    List<Room> selectCountSearch(@Param("roomtype") String roomtype,@Param("userName3") String userName3);

    @Update("update room set room_state = #{rs} where room_id = #{roomId}")
    @ResultMap("RoomResultMap")
    int deleteReserve(@Param("roomId") String roomId,@Param("rs") String rs);

    @Select("select * from room where room_state = #{roomState1} or room_state = #{roomState2} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPage1(@Param("start") int start,@Param("size") int size,@Param("roomState1") String roomState1,@Param("roomState2") String roomState2);

    @Select("select * from room where room_state = #{roomState1} or room_state = #{roomState2}")
    @ResultMap("RoomResultMap")
    List<Room> selectCount1(@Param("roomState1") String roomState1,@Param("roomState2") String roomState2);

    @Select("select * from room where room_state = #{roomState} and room_type = #{roomType} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPage2(@Param("start") int start,@Param("size") int size,@Param("roomState") String roomState,@Param("roomType") String roomType);

    @Select("select * from room where room_state = #{roomState} and room_type = #{roomType}")
    @ResultMap("RoomResultMap")
    List<Room> selectCount2(@Param("roomState") String roomState,@Param("roomType") String roomType);

    @Select("select * from room where room_state = #{roomtype} and room_id = #{selectroomid} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPageSelectid(@Param("start") int start,@Param("size") int size,@Param("roomtype") String roomtype,@Param("selectroomid") String selectroomid);

    @Select("select * from room where room_state = #{roomtype} and room_id = #{selectroomid}")
    @ResultMap("RoomResultMap")
    List<Room> selectCountSelectid(@Param("roomtype") String roomtype,@Param("selectroomid") String selectroomid);

    @Update("update room set room_out =#{outRoomTime},room_time =#{roomtime} where room_id =#{roomid}")
    @ResultMap("RoomResultMap")
    int updateRoomDate(@Param("outRoomTime") String outRoomTime,@Param("roomtime") int roomtime,@Param("roomid") String roomid);

    @Select("select * from room where (room_state = #{roomState1} or room_state = #{roomState2}) and room_type = #{singleroom} limit #{start},#{size}")
    @ResultMap("RoomResultMap")
    List<Room> findByPageSingle(@Param("start") int start,@Param("size") int size,@Param("roomState1") String roomState1,@Param("roomState2") String roomState2,@Param("singleroom") String singleroom);

    @Select("select * from room where (room_state = #{roomState1} or room_state = #{roomState2}) and room_type = #{singleroom}")
    @ResultMap("RoomResultMap")
    List<Room> selectCountSingle(@Param("roomState1") String roomState1,@Param("roomState2") String roomState2,@Param("singleroom") String singleroom);
}